package entity;

import java.util.List;
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 *
 * @author TWD
 */
@Entity
public class Stakeholder implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id 
    @Column(unique = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    private Integer loyaltyPoints;
    private String email;
    private boolean purchaseBI;
    
    @ManyToOne(cascade = {CascadeType.PERSIST})
    private StakeholderTier stakeholderTier;
    
    
    //private List<RepresentativeEntity> representative;
    
    @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "stakeholder")
    private List<Advertisement> Advertisement;
    
    @OneToMany(cascade={CascadeType.ALL}, mappedBy = "stakeholderEntity")
    private List<StakeholderBill> stakeholderBill;
    
    @OneToMany(cascade={CascadeType.ALL}, mappedBy = "stakeholder")
    private List<GroupBuyingItem> groupon;
    
    public boolean create(String name, Integer loyaltyPoints, StakeholderTier stakeholderTier, String email){
        
        try{
            this.name = name;
            this.loyaltyPoints = loyaltyPoints;
            this.setStakeholderTier(stakeholderTier);   
            this.email = email;
            
            return true;
            
        }catch(Exception ex){        
            return false;            
        }
    }
    
    public void addGroupBuyingItem(GroupBuyingItem gbi){
        this.groupon.add(gbi);
    }

    public String getName(){
        return name;
    }

    public void setName(String name){
        this.name = name;
    }

    public Integer getLoyaltyPoints(){
        return loyaltyPoints;
    }

    public void setLoyaltyPoints(Integer loyaltyPoints){
        this.loyaltyPoints = loyaltyPoints;
    }

    public List<StakeholderBill> getStakeholderBill(){
        return stakeholderBill;
    }

    public void setStakeholderBill(List<StakeholderBill> stakeholderBill){
        this.setStakeholderBill(stakeholderBill);
    }

    public StakeholderTier getStakeholderTier(){
        return stakeholderTier;
    }

    public void setStakeholderTier(StakeholderTier stakeholderTier){
        this.stakeholderTier = stakeholderTier;
    }

    public List<Advertisement> getAdvertisement(){
        return Advertisement;
    }

    public void setAdvertisement(List<Advertisement> Advertisement){
        this.setAdvertisement(Advertisement);
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public List<GroupBuyingItem> getGroupon() {
        return groupon;
    }

    public void setGroupon(List<GroupBuyingItem> groupon) {
        this.groupon = groupon;
    }
    
    public boolean isPurchaseBI() {
        return purchaseBI;
    }

    public void setPurchaseBI(boolean purchaseBI) {
        this.purchaseBI = purchaseBI;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

}
